package com.jh.user.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;

/**
 * 快银支付通道信息
 */
@Entity
@Table(name = "t_congming_channel")
public class CongMingChannel implements Serializable {
    private static final long serialVersionUID = -4667416984965701090L;

    @Id
    @Column(name = "id")
    private long id;

    /** 通道标识 */
    @Column(name = "channelTag")
    private String channelTag;

    /** 传到通道的参数, 集成的商家类的 */
    @Column(name = "channel_param")
    private String channelParam;

    /** 通道商家标号 */
    @Column(name = "channel_no")
    private String channelNo;

    /** 通道名字 */
    @Column(name = "name")
    private String name;

    /** 通道状态0:关闭；1：正常使用； */
    @Column(name = "status")
    private String status;

    /** 子通道名字 */
    @Column(name = "sub_name")
    private String subName;

    /** 描述 */
    @Column(name = "remarks")
    private String remarks;

    /** 通道开始时间 */
    @Column(name = "start_time")
    private String startTime;

    /** 通道结束时间 */
    @Column(name = "end_time")
    private String endTime;

    /** 通道费率 */
    @Column(name = "rate")
    private BigDecimal rate = BigDecimal.ZERO;

    /** 创建时间 */
    @Column(name = "create_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getChannelTag() {
        return channelTag;
    }

    public void setChannelTag(String channelTag) {
        this.channelTag = channelTag;
    }

    public String getChannelParam() {
        return channelParam;
    }

    public void setChannelParam(String channelParam) {
        this.channelParam = channelParam;
    }

    public String getChannelNo() {
        return channelNo;
    }

    public void setChannelNo(String channelNo) {
        this.channelNo = channelNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getSubName() {
        return subName;
    }

    public void setSubName(String subName) {
        this.subName = subName;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public BigDecimal getRate() {
        return rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CongMingChannel)) return false;
        CongMingChannel that = (CongMingChannel) o;
        return getId() == that.getId() &&
                getChannelTag() == that.getChannelTag() &&
                Objects.equals(getChannelParam(), that.getChannelParam()) &&
                Objects.equals(getChannelNo(), that.getChannelNo()) &&
                Objects.equals(getName(), that.getName()) &&
                Objects.equals(getStatus(), that.getStatus()) &&
                Objects.equals(getSubName(), that.getSubName()) &&
                Objects.equals(getRemarks(), that.getRemarks()) &&
                Objects.equals(getStartTime(), that.getStartTime()) &&
                Objects.equals(getEndTime(), that.getEndTime()) &&
                Objects.equals(getRate(), that.getRate()) &&
                Objects.equals(getCreateTime(), that.getCreateTime());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getChannelTag(), getChannelParam(), getChannelNo(), getName(), getStatus(), getSubName(), getRemarks(), getStartTime(), getEndTime(), getRate(), getCreateTime());
    }

    @Override
    public String toString() {
        return "CongMingChannel{" +
                "id=" + id +
                ", channelTag=" + channelTag +
                ", channelParam='" + channelParam + '\'' +
                ", channelNo='" + channelNo + '\'' +
                ", name='" + name + '\'' +
                ", status='" + status + '\'' +
                ", subName='" + subName + '\'' +
                ", remarks='" + remarks + '\'' +
                ", startTime='" + startTime + '\'' +
                ", endTime='" + endTime + '\'' +
                ", rate='" + rate + '\'' +
                ", createTime=" + createTime +
                '}';
    }

    public void addCongMingChannel(CongMingChannelRequest channelRequest) {
        setChannelNo(channelRequest.getChannelNo());
        setChannelParam(channelRequest.getChannelParam());
        setChannelTag(channelRequest.getChannelTag());
        setName(channelRequest.getName());
        setRate(new BigDecimal(channelRequest.getRate()));
        setRemarks(channelRequest.getRemarks());
        setStatus(channelRequest.getStatus());
        setSubName(channelRequest.getSubName());
        setCreateTime(Calendar.getInstance().getTime());
    }

    public Map<String, Object> getCongMingChannelInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("channelNo", getChannelNo());
        map.put("channelParam", getChannelParam());
        map.put("channelTag", getChannelTag());
        map.put("createTime", getCreateTime());
        map.put("id", getId());
        map.put("name", getName());
        map.put("rate", getRate());
        map.put("remark", getRemarks());
        map.put("status", getStatus());
        map.put("subName", getSubName());
        return map;
    }
}
